package cn.iocoder.yudao.module.nmkj.dal.mysql.article;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.nmkj.dal.dataobject.article.ArticleDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.nmkj.controller.admin.article.vo.*;

/**
 * 文章管理 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ArticleMapper extends BaseMapperX<ArticleDO> {

    default PageResult<ArticleDO> selectPage(ArticlePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ArticleDO>()
                .eqIfPresent(ArticleDO::getImg, reqVO.getImg())
                .eqIfPresent(ArticleDO::getTitle, reqVO.getTitle())
                .betweenIfPresent(ArticleDO::getArticleTime, reqVO.getArticleTime())
                .eqIfPresent(ArticleDO::getContent, reqVO.getContent())
                .eqIfPresent(ArticleDO::getBindArticleId, reqVO.getBindArticleId())
                .eqIfPresent(ArticleDO::getSort, reqVO.getSort())
                .eqIfPresent(ArticleDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(ArticleDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ArticleDO::getStatus)
                .orderByDesc(ArticleDO::getSort));
    }

    default PageResult<ArticleDO> selectPageList(ArticlePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ArticleDO>()
                .betweenIfPresent(ArticleDO::getStatus, new Integer[] {0, 1})
                .orderByDesc(ArticleDO::getSort));
    }

}